﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SPIWareMVVM.ViewModels;
using System.Windows.Controls;
using DataAccess;

namespace SPIWareMVVM.Views.Commands
{
    public class ViewAllPartsCommand : BaseCommand
    {
        public ViewAllPartsCommand(BaseViewModel sender) : base(sender)
        {
            _sender = (WorkOrdersViewModel)sender;
        }

        public override void Execute(object parameter)
        {
            ComboBox cb = null;
            if (parameter != null) cb = (ComboBox)parameter;
            if (cb != null)
            {
                //Previous version
                //cb.ItemsSource = null;
                //cb.ItemsSource = ApplicationData.ocParts;

                //Attempted new version
                ApplicationData.ShowAllWOParts = !ApplicationData.ShowAllWOParts;
                cb.ItemsSource = null;
                System.Collections.ObjectModel.ObservableCollection<Part> partsList = ApplicationData.ocParts;
                
                //if (applicationViewModel.SelectedCustomer != null) partsList = partsList.GetByCustomer(applicationViewModel.SelectedCustomer);
                if (!ApplicationData.ShowAllWOParts) partsList = partsList.GetByCustomer(ApplicationData.SelectedWorkOrder.Customer);
                cb.ItemsSource = partsList;
            }
        }
    }
}
